<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
	<base href="<%=basePath%>"><!-- jsp文件头和头部 -->
	<%@ include file="../../system/main/main_top.jsp"%> 
	
    <link rel="stylesheet" media="screen" type="text/css" href="static/select2-js/select2.css" />
	</head>
<body>
<div class="container-fluid" id="main-container">
<div id="breadcrumbs">
	<ul class="breadcrumb">
		<li><i class="icon-home"></i> <a>统计报表</a> <span class="divider">
				<i class="icon-angle-right"></i>
		</span></li>
		<li class="active">推广人员结算报表</li>
	</ul>
	<!--.breadcrumb-->
</div>
<div id="page-content" class="clearfix">
  <div class="row-fluid">
	<div class="row-fluid">
			<!-- 检索  -->
			<form action="busiSpreadReport/list.do" method="post" name="Form" id="Form">
			<table>
				<tr>
					<td><input class="span10 date-picker" id="lastStart" name="lastStart" value="${pd.lastStartShow}" type="text" data-date-format="yyyy-mm-dd" readonly="readonly" style="width:120px;" placeholder="交易时间从"/></td>
					<td><input class="span10 date-picker" id="lastEnd" name="lastEnd" value="${pd.lastEndShow}" type="text" data-date-format="yyyy-mm-dd" readonly="readonly" style="width:120px;" placeholder="交易时间至"/></td>
					<td>&nbsp;&nbsp;</td>
					<td style="vertical-align:top;">
						<input type="text" id="keyword" name="keyword" value="${pd.keyword}" placeholder="这里输入推广员手机号码"/>
					</td>
					<td>&nbsp;&nbsp;</td>
					<td style="vertical-align:top;">
						受邀状态：
						<select class="chzn-select" name="status" id="status" data-placeholder="请选择受邀状态" style="vertical-align:top;width: 120px;">
							<option value="-1" <c:if test="${pd.status=='' || pd.status==null}">selected</c:if>>全部</option>
							<option value="1" <c:if test="${pd.status=='1'}">selected</c:if>>有效</option>
							<option value="2" <c:if test="${pd.status=='2'}">selected</c:if>>无效</option>
					  	</select>
					</td>
					<td style="vertical-align:top;">
						核算状态：
						<select class="chzn-select" name="check_state" id="check_state" data-placeholder="请选择核算状态" style="vertical-align:top;width: 120px;">
							<option value="-1" <c:if test="${pd.check_state=='' || pd.check_state==null}">selected</c:if>>全部</option>
							<option value="1" <c:if test="${pd.check_state=='1'}">selected</c:if>>未核算</option>
							<option value="2" <c:if test="${pd.check_state=='2'}">selected</c:if>>已核算</option>
					  	</select>
					</td>
					<td style="vertical-align:top;"><a class="btn btn-mini btn-light" onclick="searchStatement();"  title="检索"><i id="nav-search-icon" class="icon-search"></i></a></td>
					<td style="vertical-align:top;"><a class="btn btn-mini btn-light" onclick="exportExcel();" title="导出到EXCEL"><i id="nav-search-icon" class="icon-download-alt"></i></a></td>
				</tr>
			</table>
			<div class="Noprint">
				<i class="icon-circle green"></i>温馨提示：<strong>默认显示从当前月份往前7天的数据</strong>
			</div>
			<!-- 检索  -->
			<table id="table_report" class="table table-striped table-bordered table-hover" style="margin-top: 10px;">
				<thead>
					<tr>
						<th>邀请码</th>
						<th>推广员手机号码</th>
						<th>受邀状态</th>
						<th>核算金额</th>
						<th>平台实际到账金额X</th>
						<th>补贴金额X*0.6%</th>
						<th>最终钱包余额X+X*0.6%</th>
						<th>用户申请提现金额 Y</th>
						<th>扣除手续费（Y*0.5%)最低1元 最高25元</th>
						<th>最终可提现金额（Y-Y*0.5%）</th>
						<th>核算状态（已经扣款，暂未扣款。财务人员进行处理）</th>
						<th>创建时间</th>
						<th>推广员账户信息</th>
						<th>支付批次号</th>
						<th>付款状态</th>
						<th>所属商户</th>
						<th class="center">操作</th>
					</tr>
				</thead>
										
				<tbody>
					
				<!-- 开始循环 -->	
				<c:choose>
					<c:when test="${not empty varList}">
						<c:forEach items="${varList}" var="var" varStatus="vs">
							<tr>
									<td>${var.invitation_code}</td>
									<td>${var.spread_mobile}</td>
									<td>
										<c:if test="${var.status == '1' }">有效</c:if>
										<c:if test="${var.status == '2' }">无效</c:if>
									</td>
									<td>${var.total_amount}</td>
									<td>${var.rece_actual_amount}</td>
									<td>${var.subsidy_amount}</td>
									<td>${var.final_rece_amount}</td>
									<td>${var.apply_withdraw_amount}</td>
									<td>${var.commission_amount}</td>
									<td>${var.final_withdraw_amount}</td>
									<td>
										<c:if test="${var.check_state == '1' }">未核算</c:if>
										<c:if test="${var.check_state == '2' }">已核算</c:if>
									</td>
									<td>${pd.lastStartShow}-${pd.lastEndShow}</td>
									<td>
										${var.account_info}
									</td>
									<td>
										${var.batch_no}
									</td>
									<td>
										<c:if test="${var.pay_status == '0' }">未付款</c:if>
										<font color="green"><c:if test="${var.pay_status == '1' }">付款成功</c:if></font>
										<font color="red"><c:if test="${var.pay_status == '2' }">付款失败</c:if></font>
									</td>
									<td>
										${var.organ_name}
									</td>
									<td class="center">
										<div>
											<a class='btn btn-mini btn-info' title="详情" onclick="view('${var.spread_mobile}','${var.status}','${var.check_state}',2);" style="margin-top: 2px;">详情</a>
										</div>
									</td>
							</tr>
						</c:forEach>
						<!-- 
						<tr>
							<td colspan="100" class="center">您无权查看</td>
						</tr>
						 -->
					</c:when>
					<c:otherwise>
						<tr class="main_info">
							<td colspan="100" class="center" >没有相关数据</td>
						</tr>
					</c:otherwise>
				</c:choose>
				</tbody>
			</table>
			
			<div class="page-header position-relative">
				<table style="width:100%;">
					<tr>
						<td style="vertical-align:top;">
							<!-- <a class="btn btn-small btn-success" onclick="view(1);">查看</a> -->
						</td>
						<td style="vertical-align:top;"><div class="pagination" style="float: right;padding-top: 0px;margin-top: 0px;">${page.pageStr}</div></td>
					</tr>
				</table>
			</div>
		</form>
	</div>
 
	<!-- PAGE CONTENT ENDS HERE -->
  </div><!--/row-->
	
</div><!--/#page-content-->
</div><!--/.fluid-container#main-container-->
			<form action="busiSpreadReport/editBusiSpreadReport.do" method="post" name="busiSpreadReportForm" id="busiSpreadReportForm">
				<input type="hidden" name="lastStartEdit" id="lastStartEdit"/>
				<input type="hidden" name="lastEndEdit" id="lastEndEdit"/>
				<input type="hidden" name="keywordEdit" id="keywordEdit"/>
				<input type="hidden" name="check_stateEdit" id="check_stateEdit"/>
				<input type="hidden" name="statusEdit" id="statusEdit"/>
			</form>
			<div align="center">
				<a class="btn btn-primary" onclick="save();">核算</a>
			</div>
	
		<!-- 返回顶部  -->
		<a href="#" id="btn-scroll-up" class="btn btn-small btn-inverse">
			<i class="icon-double-angle-up icon-only"></i>
		</a>
		
		<!-- 引入 -->
		<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
		<script type="text/javascript" src="static/js/bootstrap.min.js"></script>
		<script type="text/javascript" src="static/js/ace-elements.min.js"></script>
		<script type="text/javascript" src="static/js/ace.min.js"></script>
		<script type="text/javascript" src="static/select2-js/select2.js"></script>
		<script type="text/javascript" src="static/select2-js/select2.min.js"></script>
		<script type="text/javascript" src="static/select2-js/select2_locale_zh-CN.js"></script>
		<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->	
		<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
		<script type="text/javascript" src="static/js/bootstrap-datepicker.min.js"></script><!-- 日期框 -->
		<!-- 引入 -->
		
		<script type="text/javascript">
		
		$(top.hangge());
		
		//下拉框
		$(".chzn-select").chosen(); 
		$(".chzn-select-deselect").chosen({allow_single_deselect:true}); 
		
		$(function() {
			//单选框
			$(".chzn-select").chosen(); 
			$(".chzn-select-deselect").chosen({allow_single_deselect:true}); 
			//日期框
			$('.date-picker').datepicker();
		});
		
		//检索
		function searchStatement(){
			var start = $("#lastStart").val();  
		    var end = $("#lastEnd").val();  
		    if(start != null && end != null){
		        if(end < start){  
		            alert('结束时间不能早于开始时间！');  
		            $("#lastEnd").focus();  
		            return false;  
		        }  
		          
		        var days = daysBetween(start,end);  
		        if(days>7){  
		            alert('时间跨度不能超过7天！');  
		            $("#lastEnd").focus();  
		            return false;  
		        }  
		    }  

			$("#Form").submit();
		}
		
		//+--------------------------------------------------    
		//| 求两个时间的天数差 日期格式为 YYYY-MM-dd     
		//+--------------------------------------------------  
		function daysBetween(DateOne,DateTwo)    
		{     
		    var OneMonth = DateOne.substring(5,DateOne.lastIndexOf ('-'));    
		    var OneDay = DateOne.substring(DateOne.length,DateOne.lastIndexOf ('-')+1);    
		    var OneYear = DateOne.substring(0,DateOne.indexOf ('-'));    
		    
		    var TwoMonth = DateTwo.substring(5,DateTwo.lastIndexOf ('-'));    
		    var TwoDay = DateTwo.substring(DateTwo.length,DateTwo.lastIndexOf ('-')+1);    
		    var TwoYear = DateTwo.substring(0,DateTwo.indexOf ('-'));    
		    
		    var cha=((Date.parse(OneMonth+'/'+OneDay+'/'+OneYear)- Date.parse(TwoMonth+'/'+TwoDay+'/'+TwoYear))/86400000);     
		    return Math.abs(cha);    
		}  
		
		
		//查看
		function view(spread_mobile,status,check_state,flag){
			 var lastStart = $("#lastStart").val();  
		     var lastEnd = $("#lastEnd").val();  
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="详情";
			 diag.URL = '<%=basePath%>/busiSpreadReport/listDetail.do?lastStart='+lastStart+'&lastEnd='+lastEnd+'&check_state='+check_state+'&status='+status+'&keyword='+spread_mobile+'&flag='+flag;
			 diag.Width = 1200;
			 diag.Height = 800;
			 diag.CancelEvent = function(){ //关闭事件
				 if(diag.innerFrame.contentWindow.document.getElementById('centerOfMainFrame').style.display == 'none'){
					 nextPage(${page.currentPage});
				}
				diag.close();
			 };
			 diag.show();
		}
		
		function movieFormatResult(result, container, query, escapeMarkup) {
			return result.text;
		}
		
		function exportExcel(){
			var lastStart = $("#lastStart").val();  
		    var lastEnd = $("#lastEnd").val();  
			var status = $("#status").val();
			var keyword = $("#keyword").val();
			var check_state = $("#check_state").val();
			window.location.href='<%=basePath%>/busiSpreadReport/exportExcel.do?lastStart='+lastStart+'&lastEnd='+lastEnd+'&status='+status+'&keyword='+keyword+'&check_state='+check_state;
		}
		
		//保存
		function save(){
			bootbox.confirm("<font color='red'>确认核算吗? 状态一旦修改则不能恢复!</font>", function(result) {
				if(result) {
					var lastStart = $("#lastStart").val();  
				    var lastEnd = $("#lastEnd").val();  
					var status = $("#status").val();
					var keyword = $("#keyword").val();
					var check_state = $("#check_state").val();
					if(status != 1 || check_state != 1){
						alert("核算状态或受邀状态不正确，无效的提交动作！");
						return false;
					}
					$("#lastStartEdit").val(lastStart);
					$("#lastEndEdit").val(lastEnd);
					$("#statusEdit").val(status);
					$("#keywordEdit").val(keyword);
					$("#check_stateEdit").val(check_state);
					
					$("#busiSpreadReportForm").submit();
					//var url = "<%=basePath%>/busiSpreadReport/editBusiSpreadReport.do?lastStartEdit=" + lastStart + "&lastEndEdit=" + lastEnd+ "&statusEdit=" + status+ "&keywordEdit=" + keyword+ "&check_stateEdit=" + check_state;
					//var url = "<%=basePath%>/busiSpreadReport/editBusiSpreadReport/"+lastStart + "/" + lastEnd+ "/" + status+ "/" + check_state + "/" + keyword + ".json";
					/* $.ajax({
						type : "POST",
						url : url,
						//data:JSON.stringify(catacode),
						contentType:"application/json",  //发送至服务器的类型
						dataType : "json",     //预期服务器返回类型
						success: function(data){
							//alert(data.string);
							//return false;
							if(data.string=="success"){
								alert("操作成功!");
								document.location.reload();
							}else{
								alert("操作失败!");
							}
						}
					}) */
				}
			});
		}
		</script>
	</body>
</html>

